package jonaVisual;

import java.awt.Font;
import javax.swing.JTextArea;


import Jona.*;


public class JonaTextArea extends JTextArea {
	static final long serialVersionUID =121243812;
	public JonaTextArea()
	{
		setEditable(false);
		//Font f1 = new Font();
		
		setFont(Font.getFont("System"));
	}
	
	
	public void visualize1(ArgObject head)
	{
		setText("Visualisation1 on NEW MODEL:\n\n" + drawSimpleTree2(head,""));		
	}
	
	public void visualize2(ArgObject head)
	{
		setText("Visualisation2 on NEW MODEL:\n\n" + drawSimpleTree3(head,""));
	}	
	
	public void visualize(ArgObject head)
	{
		setText("Visualisation on OLD MODEL:\n\n" + drawSimpleTree(head,""));
	}
	
	public String getClassName(ArgObject s1)
	{
		String rt = s1.getClass().getName();

		return rt;
	}
		
	public String drawSimpleTree3(ArgObject s1,String indent)
	{
		String rt ="";
		if(s1.getClass().getSimpleName().equals("Statement") || s1.getClass().getSimpleName().equals("Negation"))
		{
			String type ="";
			
			if(s1.getArgumentType() ==Statement.ISSUE )
			{
				type += "(ISSUE)";
			}
			else if(s1.getArgumentType() == Statement.ASSUMPTION)
			{
				type += "(ASSUMPTION)";
			}
			else if(s1.getArgumentType() == Statement.UNDEFINED)
			{
				type+="(STATEMENT)";
			}
			
			//rt+=")\n";
			//StatementNode n1 = s1.getSupportingConditionals().giveFirst();
			//Object o1;
			for(int i =0; i < s1.getSupportingConditionals().length; i++)
			{	
				//rt += n1.o1.getClass().getSimpleName() + " \n";
				if(s1.getSupportingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
				{
					rt+= indent + " + " + s1.getText() + type + "\n";
					rt += indent + "	|\n";
					rt+= drawSimpleTree3(s1.getSupportingConditionals()[i],"	" + indent);
				}
			}
		
			for(int i =0; i < s1.getAttackingConditionals().length; i++)
			{	
				if(s1.getAttackingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
				{	
					rt+= indent + "	|- " + s1.getText() + type +"\n";
					rt += indent + "	|\n";
					rt+= drawSimpleTree3(s1.getAttackingConditionals()[i],"	" +indent);
				}
				//rt += n1.o1.getClass().getSimpleName() + " \n";
			}			
			
			if(s1.getSupportingConditionals().length ==0 && s1.getAttackingConditionals().length == 0)
			{
				rt += indent + s1.getText() + type + "\n";
			}
			
		}
		if(s1.getClass().getSimpleName().equals("Conditional"))
		{
			Conditional s2 = (Conditional)s1;
					
			//;StatementNode n1 = s1.getSupportingConditionals().giveFirst();
			//Object o1;
			for(int i =0; i < s1.getSupportingConditionals().length; i++)
			{
				//rt += n1.o1.getClass().getSimpleName() + " \n";
				if(s1.getSupportingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
				{
					rt+=indent+"| + ";
					//rt+= indent + " + " + s1.getText() + "\n";
					rt+= drawSimpleTree3(s1.getSupportingConditionals()[i], "");
				}
			}
			//n1 = s1.getAttackingConditionals().giveFirst();
			//Object o1;
			for(int i =0; i < s1.getAttackingConditionals().length; i++)
			{
				//rt += n1.o1.getClass().getSimpleName() + " \n";
				if(s1.getAttackingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
				{
					rt+=indent+"| - ";
					//rt+= indent + " + " + s1.getText() + "\n";
					rt+= drawSimpleTree3(s1.getAttackingConditionals()[i],indent);
				}
			}		
			if(s2.getAntecedents().length > 0)
				//rt += indent + "ANTECEDENTS\n";	
			//n1 = s2.getAntecedents().giveFirst();
			for(int i =0; i< s2.getAntecedents().length; i++)
			{
				rt += indent + "\\ ";
				rt +=drawSimpleTree3(s2.getAntecedents()[i],"");
			}			
			
		}
		
		return rt;
	}
	
	public String drawSimpleTree2(ArgObject s1,String indent)
	{
		String rt = "";
		if(s1.getClass().getSimpleName().equals("Statement") || s1.getClass().getSimpleName().equals("Negation"))
		{
			rt += indent;
			if(s1.getArgumentType() ==Statement.ISSUE )
			{
				rt += "ISSUE:: ";
			}
			if(s1.getArgumentType() == Statement.ASSUMPTION)
			{
				rt += "ASSUMPTION:: ";
			}
			if(s1.getArgumentType() == Statement.UNDEFINED)
			{
				rt+="STATEMENT:: ";
			}
			// TODO: Snelle hack door Tijs. Jelle: Bouw om wat je wil. :) Lijkt me erg simpel maar toch effectief, voor testdoeleinden prima..(Jelle)
			if (s1.getClass().getSimpleName().equals("Negation"))
				rt+="NOT: ";
			rt += s1.getText() + "\n";			
			
			if(s1.getSupportingConditionals().length > 0)
				rt += "-SUPPORTERS-\n";
			
			//StatementNode n1 = s1.getSupportingConditionals().giveFirst();
			//Object o1;
			for(int i =0; i <  s1.getSupportingConditionals().length; i++)
			{
				//rt += n1.o1.getClass().getSimpleName() + " \n";
				if(s1.getSupportingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
					rt+= drawSimpleTree2(s1.getSupportingConditionals()[i],"	" + indent);

			}
			if(s1.getAttackingConditionals().length> 0)
				rt += "-ATTACKERS-\n";
			
			for(int i =0; i < s1.getAttackingConditionals().length;i++)
			{
				if(s1.getAttackingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
					rt+= drawSimpleTree2(s1.getAttackingConditionals()[i],"	" + indent);
				//rt += n1.o1.getClass().getSimpleName() + " \n";
			}			
				
		}
		if(s1.getClass().getSimpleName().equals("Conditional"))
		{
			Conditional s2 = (Conditional)s1;
			rt += indent;
			if(s1.getArgumentType() == Statement.ISSUE )
			{
				rt += "ISSUE:: ";
			}
			else if(s1.getArgumentType() == Statement.ASSUMPTION)
			{
				rt += "ASSUMPTION:: ";
			}
			else if(s1.getArgumentType() == Statement.UNDEFINED)
			{
				rt+="STATEMENT:: ";
			}
			//rt += s1.getText() + "\n";			
			rt+= "CONDITIONAL\n";
			if(s1.getSupportingConditionals().length > 0)
				rt += indent + "-SUPPORTERS-\n";
			
			//StatementNode n1 = s1.getSupportingConditionals().giveFirst();
			//Object o1;
			for(int i = 0;i < s1.getSupportingConditionals().length;i++)
			{
				//rt += s1.getSupportingConditionals()[i].getClass().getSimpleName() + " \n";
				if(s1.getSupportingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
					rt+= drawSimpleTree2(s1.getSupportingConditionals()[i],"	" + indent);
			}
			if(s1.getAttackingConditionals().length> 0)
				rt += indent + "-ATTACKERS-\n";
			
			//n1 = s1.getAttackingConditionals().giveFirst();
			for(int i = 0;i < s1.getAttackingConditionals().length;i++)
			{
				if(s1.getAttackingConditionals()[i].getClass().getSimpleName().equals("Conditional"))
					rt+= drawSimpleTree2(s1.getAttackingConditionals()[i],"	" + indent);
				//rt += n1.o1.getClass().getSimpleName() + " \n";
			}	
			
			if(s2.getAntecedents().length > 0)
				rt += indent + "ANTECEDENTS\n";	
			
			//n1 = s2.getAntecedents().giveFirst();
			for(int i =0; i < s2.getAntecedents().length;i++)
			{
				rt +=drawSimpleTree2(s2.getAntecedents()[i],indent);
			}							
		}
		return rt;
	}
	
	public String drawSimpleTree(ArgObject s1, String indent)
	{
		String rt = "";	
		if(s1.getClass().getSimpleName().equals("Statement"))
		{
			if(s1.getArgumentType() == Statement.ISSUE )
			{
				rt += "ISSUE:: ";
			}
			if(s1.getArgumentType() == Statement.ASSUMPTION)
			{
				rt += "ASSUMPTION:: ";
			}
			if(s1.getArgumentType() == Statement.UNDEFINED)
			{
				rt+="STATEMENT:: ";
			}
			rt += s1.getText() + "\n";	
			if(s1.getSupportingConditionals().length > 0)
				rt += "-SUPPORTERS-\n";
			for(int i=0; i < s1.getSupportingConditionals().length; i++)
				rt += drawSimpleTree(s1.getSupportingConditionals()[i],"");
			
			if(s1.getAttackingConditionals().length > 0)
				rt += "-ATTACKERS-\n";
			for(int i=0; i < s1.getAttackingConditionals().length; i++)
				rt += drawSimpleTree(s1.getAttackingConditionals()[i],"");
			
		}
		if(s1.getClass().getSimpleName().equals("Conditional"))
		{
			if(s1.getArgumentType() == Statement.ISSUE )
			{
				rt += "ISSUE:: ";
			}
			if(s1.getArgumentType() == Statement.ASSUMPTION)
			{
				rt += "ASSUMPTION:: ";
			}
			if(s1.getArgumentType() == Statement.UNDEFINED)
			{
				rt+="STATEMENT:: ";
			}
			//rt += s1.getText() + "\n";			
			rt+= "CONDITIONAL\n";
			if(s1.getSupportingConditionals().length > 0)
				rt += indent + "	-SUPPORTERS-\n";
			for(int i=0; i < s1.getSupportingConditionals().length; i++)
				rt += "	" + indent + drawSimpleTree(s1.getSupportingConditionals()[i],"	");
			
			if(s1.getAttackingConditionals().length > 0)
				rt += indent +"	-ATTACKERS-\n";
			for(int i=0; i < s1.getAttackingConditionals().length; i++)
				rt += "	" + indent + drawSimpleTree(s1.getAttackingConditionals()[i],"	");		
		}		


		return rt;
	}
	
}
